<?php
if (!$_GET['id']) {
    echo "Bad Request";
}
$id = $_GET['id'];
//including header.php 
include '../../include/header.php';
//including page.php (It is a class which contain functions)
include '../../libraries/page.php';
$page = new page();
session_start();
$userid = $_SESSION['userid'];

// checking the session
if (!$_SESSION['username']) {
    header("location:../user/login.php");
}
if ($_GET['q'] == 'logout') {
    $page->user_logout();
    header("location:../user/login.php");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// for $_POST['submit'].  Remember, field names are determined by array keys!
    $result = $page->mysql_update_array("suppliers", $id, "supplierid", $_POST);
    if ($result) {
        header("location:suppliers?status='1'");
    } else {
        $msg = $message[0];
    }
}
?>

<!-----------------------------------------------content----------------------------------->

<!-------------------------------------Navbar---------------------------------->
<?
$suppliers = 'active';
include '../../include/navbar.php';
?>

   <div class="bread_crumb" style="margin-left: 2%">
       &laquo;  <a href="suppliers">Back</a>
  </div>

<!----------------------------------Display the result message of Update--------------------->
<div  align="center"><? echo $msg; ?></div>

<!----------------------------------------------div for placing form here------------------------->
<div>


    <!-----------------We are retrieving data from database table to display in the fields to update--------->
    <?
    //php code to get the data from suppliers table 
    $suppliers = mysql_query("select * from suppliers where supplierid = $id");
    $suppliers_data = mysql_fetch_array($suppliers);

    $supplier_id = $suppliers_data['supplierid'];
    $name = ucwords(strtolower($suppliers_data['name']));
    $address = ucwords(strtolower($suppliers_data['address']));
    $street = $suppliers_data['street'];
    $city = ucwords(strtolower($suppliers_data['city']));
    $state = $suppliers_data['state'];
    $mobile = $suppliers_data['mobile'];
    $phone = $suppliers_data['phone'];
    $taxid = $suppliers_data['TaxIDNumber'];
    //To get current date and time
    date_default_timezone_set('Asia/Calcutta');
    $date1 = date("Y-m-d H:i:s");
    ?>



    <!---------------------------------form------------------------------------------------>
    <form method="POST"  action="">
        <div class="maindiv">
            <h3 style="color:#777;text-align: center"> Update Supplier</h3>
            <div class="leftdiv">
                <label>Supplier name</label>
                <input class="input-xlarge" id="focusedInput" type="text" name="name" value="<? echo $name; ?>"  required>
            </div>
            <div class="middiv"></div>
            <div class="rightdiv">  <label>Address</label>
                <input class="input-xlarge"  id="focusedInput" name="address" type="text"  value="<? echo $address; ?>"  >
            </div>
            <div class="leftdiv">
                <label>Street</label>
                <input class="input-xlarge" id="focusedInput" type="text" name="street"  value="<? echo $street; ?>">
            </div>
            <div class="middiv"></div>
            <div class="rightdiv"> <label>City</label>
                <input class="input-xlarge"  id="focusedInput"  type="datetime" name="city"  value="<? echo $city; ?>"  >
            </div>
            <div class="leftdiv">
                <label>State</label>
                <select name="state" style="width: 280px">

                    <option>Andhra Pradesh</option>
                    <option>Arunachal pradesh</option>
                    <option>Andaman and Nicobar Islands</option>
                    <option>Assam</option>
                    <option>Bihar</option>
                    <option>Chattisgarh</option>
                    <option>Chandigarh</option>
                    <option>Dadar and Nagar Haveli</option>
                    <option>Daman and Diu</option>
                    <option>Delhi</option>
                    <option>Goa</option>
                    <option>Gujarat</option>
                    <option>Haryana</option>
                    <option>Himachal Pradesh</option>
                    <option>Jammu and Kashmir</option>
                    <option>Jharkhand</option>
                    <option>Karnataka</option>
                    <option>Kerala</option>
                    <option>Lakshadweep</option>
                    <option>Madhya Pradesh</option>
                    <option>Maharashtra</option>
                    <option>Manipur</option>
                    <option>Meghalaya</option>
                    <option>Mizoram</option>
                    <option>Nagaland</option>
                    <option>Orrisa</option>
                    <option>Pondicherry</option>
                    <option>Punjab</option>
                    <option>Rajasthan</option>
                    <option>Sikkim</option>
                    <option>Tamil Nadu</option>
                    <option>Tripura</option>
                    <option>Uttar Pradesh</option>
                    <option>Uttarakhand</option>
                    <option>West Bengal</option>

                </select>
            </div>
            <div class="middiv"></div>
            <div class="rightdiv">
                <label>Mobile</label>
                <input class="input-xlarge" id="focusedInput" type="tel" name ="mobile" value="<? echo $mobile; ?>" required >
            </div>
            <div class="leftdiv">
                <label>Phone</label>
                <input class="input-xlarge" id="focusedInput" type="tel" name="phone" value="<? echo $phone; ?>" required >
            </div>
            <div class="middiv"></div>
            <div class="rightdiv">    <label>Tax ID Number</label>
                <input class="input-xlarge" id="focusedInput" type="text" name="TaxIDNumber	" value="<? echo $taxid; ?>"  required>
                <input class="input-xlarge"  type="hidden" name="m_user"  value="<? echo $userid; ?>">
                <input class="input-xlarge"  type="hidden" name="m_date"  value="<? echo $date1;?>">
            </div>
            <div class="fulldiv">
                <button class="btn btn-inverse" type="submit"   style="float:right; margin-right: 45px; margin-top: 20px;">Update Supplier</button> 
            </div>
        </div>

    </form>
</div>

<?php
//including footer.php
include '../../include/footer.php';
?>
